<template>
  <q-responsive :ratio="1.18">
    <div
      class="large-video-card fit column"
      @mouseover="isHover = true"
      @mouseout="isHover = false"
    >
      <div class="cover-image col">
        <q-img
          :src="video.coverImage"
          width="100%"
          height="100%"
          fit="cover"
          @click="gotoVideo()"
        >
          <template v-slot:error>
            <div class="absolute-full flex flex-center bg-negative text-white">
              Cannot load image
            </div>
          </template>
        </q-img>
        <q-btn
          class="bookmark-btn"
          size="10px"
          icon="mdi-pin"
          color="primary"
          style="top: 8px; right: 8px"
          dense
          @click="addShortcuts"
        >
          <q-tooltip
            anchor="center left"
            self="center right"
            :offset="[0, 0]"
            transition-show="fade"
            transition-hide="fade"
          >
            <div class="bookmark-btn-tooltip">PIN TO SHOTCUTS</div>
          </q-tooltip>
        </q-btn>
        <q-btn
          class="bookmark-btn"
          size="10px"
          icon="mdi-playlist-plus"
          color="primary"
          style="top: 40px; right: 8px"
          dense
          @click="addPlaylist"
          v-show="isHover"
        >
          <q-tooltip
            anchor="center left"
            self="center right"
            :offset="[0, 0]"
            transition-show="fade"
            transition-hide="fade"
          >
            <div class="bookmark-btn-tooltip">SAVE TO PLAYLIST</div>
          </q-tooltip>
        </q-btn>
        <div
          class="translations-container row q-gutter-x-xs"
          v-if="!hideLanguages"
        >
          <lang-chip
            v-for="(lang, index) in video.languages"
            :key="index"
            @click="gotoVideo(lang)"
            :code="lang"
          >
          </lang-chip>
        </div>
        <div class="duration-text">{{ video.durationLabel }}</div>
      </div>
      <div class="info-container row q-pl-sm no-wrap full-width">
        <q-btn round class="avatar" :ripple="false">
          <q-avatar size="58px">
            <img :src="video.creatorAvatar" />
          </q-avatar>
        </q-btn>

        <div class="col info column q-ml-sm">
          <div class="hover-info text-no-wrap" v-show="isHover">
            {{ video.creatorName }} · {{ video.createTimeHuman }}
          </div>
          <div class="video-title q-my-sm one-line-text">{{ video.title }}</div>
          <div class="video-details row items-center no-wrap">
            <q-icon name="mdi-podium label"></q-icon>
            <div class="label">{{ video.complimentsCount }}</div>
            <q-icon class="q-ml-sm label" name="mdi-eye"></q-icon>
            <div class="q-mr-sm label">{{ video.viewCount }}</div>
            <q-icon name="img:/icons/video-info-record.svg" />
            <div class="label">{{ video.audioCount }}</div>
          </div>
        </div>
      </div>
      <div
        v-if="translator"
        class="translator-container row items-center justify-between no-wrap q-px-sm"
      >
        <div class="row">
          <q-avatar class="q-mx-sm" size="40px">
            <img
              :src="
                video.currentAudio
                  ? video.currentAudio.creatorAvatar
                  : video.creatorAvatar
              "
            />
          </q-avatar>
          <div class="text-no-wrap">
            {{
              video.currentAudio
                ? video.currentAudio.creatorName
                : video.creatorName
            }}
          </div>
        </div>
        <div class="row" v-if="video.currentAudio">
          <h-icon-num icon="mdi-play" :label="video.currentAudio.playCount" />
          <h-icon-num icon="mdi-star" :label="video.currentAudio.starCount" />
          <lang-chip :code="video.currentAudio.langCode"></lang-chip>
        </div>
      </div>
    </div>
  </q-responsive>
</template>
<script lang="ts">
import { defineComponent, ref, PropType } from 'vue';
import { useRouter } from 'vue-router';
import Video from 'src/models/Video';
import HIconNum from '../utils/HIconNum.vue';
import LangChip from '../LanguageChip.vue';
import PinnedItem, { ShortcutsType } from 'src/models/PinnedItem';
import { useUserStore } from 'src/stores/user-store';
export default defineComponent({
  props: {
    video: {
      required: true,
      type: Object as PropType<Video>,
    },
    translator: {
      type: Boolean,
      default: true,
    },
    hideLanguages: {
      type: Boolean,
      default: false,
    },
  },
  components: {
    HIconNum,
    LangChip,
  },
  setup(props) {
    const userStore = useUserStore();
    const router = useRouter();
    const isHover = ref(false);
    return {
      isHover,
      gotoVideo(lang = '') {
        if (props) {
          void router.push({
            name: 'Video',
            params: {
              id: props.video.id,
              lang: lang,
            },
          });
        }
      },
      async addShortcuts() {
        await userStore.pin({
          type: ShortcutsType.VIDEO,
          id: props.video.id,
        });
      },
      addPlaylist() {
        console.log('Adding to Bookmark');
      },
    };
  },
});
</script>
<style lang="sass" scoped>

.large-video-card
  cursor: default
  .cover-image
    position: relative
    .bookmark-btn
      position: absolute
      z-index: 1
      top: 4px
      right: 4px
      width: 28px
      height: 28px

    .duration-text
      position: absolute
      bottom: 4px
      right: 4px
      font-size: 9px
      background-color: #1c1c1c
      padding: 2px 4px

    .translations-container
      height: 32px
      position: absolute
      top: 4px
      left: 4px
      .chip
        padding: 10px 6px
        margin: 1px
        color: #b7b7b7
        background: rgba(16, 16, 16, 0.8)
  .info-container
    position: relative
    height: 62px
    max-width: 100%
    width: 100%
    background-color: #1c1c1c
    box-shadow: 0px 5px 6px rgba(0, 0, 0, 0.4)
    z-index: 3
    .avatar
      width: 66px
      height: 66px
      top: -24px
      background: #1c1c1c

    .info
      position: relative
      .hover-info
        top: -24px
        position: absolute
        background: rgba(16, 16, 16, 0.8)
        padding: 2px 4px
        border-radius: 4px
        font-size: 12px

      .video-title
        font-size: 16px
        color: #f9f9f9
        max-width: 99%

      .video-details
        .label
          color: $sub
          font-size: 12px
  .translator-container
    background-color: #242424
    height: 62px
</style>
<style lang="sass">

.bookmark-btn-tooltip
  font-size: 10px
  line-height: 28px
  height: 28px
  padding: 0px 8px
  background-color: #060606
</style>
